import uuid
from django.db import models


class WXUser(models.Model):
    """
    微信用户模型
    """
    # 基础信息
    openid = models.CharField(max_length=30, unique=True, verbose_name='微信openid')
    unionid = models.CharField(max_length=64, blank=True, null=True, verbose_name='微信unionid')
    nickname = models.CharField(max_length=64, blank=True, verbose_name='昵称')
    avatar_url = models.URLField(blank=True, verbose_name='头像URL')

    # 用户详细信息
    gender = models.PositiveSmallIntegerField(
        choices=((0, '未知'), (1, '男'), (2, '女')),
        default=0,
        verbose_name='性别'
    )
    introduce = models.CharField(max_length=64, blank=True, verbose_name='简介')

    # 时间信息
    last_login_time = models.DateTimeField(auto_now=True, verbose_name='最后登录时间')
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    class Meta:
        verbose_name = '微信用户'
        verbose_name_plural = verbose_name
        ordering = ['-created_time']

    def __str__(self):
        return self.nickname

#创建菜单模型
class FoodMenu(models.Model):
    food_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    creater_id=models.CharField(max_length=30,blank=True,verbose_name='创建者ID')
    team_id = models.CharField(max_length=16,blank=True,verbose_name='小组ID')
    type = models.PositiveSmallIntegerField(
        choices=((0, '系统菜单'), (1, '用户菜单'), (2, '小组菜单')),
        default=0,
        verbose_name='菜单类型'
    )
    name = models.CharField(max_length=100,blank=False,verbose_name='菜名')
    food_img = models.UUIDField(blank=True,null=True, verbose_name='菜品图片')
    updated_time = models.DateTimeField(auto_now=True, null=True ,verbose_name='更新时间')
    created_time = models.DateTimeField(auto_now_add=True,  verbose_name='创建时间')

    class Meta:
        verbose_name = '菜品名单'
        verbose_name_plural = verbose_name
        ordering = ['-created_time']

    def __str__(self):
        return self.name



#创建小组模型
class Team(models.Model):
    team_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    name = models.CharField(max_length=100, blank=False, verbose_name='小组名称')
    updated_time = models.DateTimeField(auto_now_add=True, verbose_name='更新时间')
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    class Meta:
        verbose_name = '小组'
        verbose_name_plural = verbose_name
        ordering = ['-created_time']

    def __str__(self):
        return self.name

#创建小组-成员模型
class Member(models.Model):
    meber_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    creater_id = models.CharField(max_length=30, blank=True, verbose_name='用户ID')
    team_id = models.CharField(max_length=16, blank=True, verbose_name='小组ID')
    role = models.PositiveSmallIntegerField(
        choices=((0, '队长'), (1, '组员')),
        default=0,
        verbose_name='角色'
    )

    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    class Meta:
        verbose_name = '成员-小组'
        verbose_name_plural = verbose_name
        ordering = ['-created_time']

